package com.shinbada.core.persistence.genrule;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/**
 * 采用枚举的方式实现单例模式
 * 各个模块分别创建枚举类，让规则生成编号易维护，易扩展
 *
 * @author initcap
 * @date Created in 2020/11/25 22:14.
 */
@Slf4j
@Getter
public enum PostPreIdGenRuleEnumSingleton implements IPostPreIdGenRule {

    DEFAULT_ID_GEN_RULE("SHIN", "SIOT", 5, () -> "SHIN00001SIOT");

    private String pre;

    private String post;

    private Integer length;

    private RuleMapper ruleMapper;

    PostPreIdGenRuleEnumSingleton(String pre, String post, Integer length, RuleMapper ruleMapper) {
        this.pre = pre;
        this.post = post;
        this.length = length;
        this.ruleMapper = ruleMapper;
    }

    public static void main(String[] args) {
        log.info("指定前缀后缀的代码主键生成器 : {}", PostPreIdGenRuleEnumSingleton.DEFAULT_ID_GEN_RULE.genCode());
    }
}
